package com.lianxian.xindong.old.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.lianxian.xindong.old.R;

public class BottomNavigateActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bottom_navigate);
        BottomNavigationView navView = findViewById(R.id.nav_view);
//        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
//                R.id.navigation_home, R.id.navigation_friend, R.id.navigation_notifications,R.id.navigation_my)
//                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
//        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(navView, navController);
    }
    //获取屏幕宽高（包含虚拟按键）

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dip(Context context, float pxValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        int x = (int) (pxValue / scale + 0.5f);
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
    public int getScreenHeightOrWidthDP(Activity context,int flag) {
        DisplayMetrics DM = new DisplayMetrics();
        Display display = context.getWindowManager().getDefaultDisplay();
        if (Build.VERSION.SDK_INT < 17)
            display.getMetrics(DM);
        else
            display.getRealMetrics(DM);

        if (flag==0){
            return px2dip(context,DM.widthPixels);
        }else if (flag==1){
            return px2dip(context,DM.heightPixels);
        }
        return -1;
    }

//    String getDisplayMetrics() {
//        DisplayMetrics DM = new DisplayMetrics();
//        Display display = getWindowManager().getDefaultDisplay();
//        if (Build.VERSION.SDK_INT < 17)
//            display.getMetrics(DM);
//        else
//            display.getRealMetrics(DM);
//
//        System.out.println("xxx");
//        return "分辨率：" + DM.widthPixels + " X " + DM.heightPixels;
//    }

    //获取状态栏高度
    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height",
                "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
}